﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;
using System.Text;
using NickLee.Common;

namespace GPCSC.Web.sjs
{
    public partial class BS :  PageBase
    {
        public StringBuilder xjc = new StringBuilder();//下基层调研天数
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                f_build();
            }
        }
        protected void f_build()
        {
            xjc.Clear();
            DataSet ds = new DataSet();
            byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
            Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
            Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];
            Hashtable htable = new Hashtable();

            htable.Add("@postid",users.CL_POSTID_PK.ToString());
            ds = new SqlReadXml().ReaderDataSet("sel_TB_HDQK_al", htable);
            if (ds.Tables.Count > 0)
            {
               
                if (ds.Tables[0].Rows.Count > 0)
                {
                    xjc.Append("<table>");
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (ds.Tables[0].Rows[i]["IsBs"].ToString() == "0")
                        {
                            ds.Tables[0].Rows[i]["title"] = "<strong style='color:red;'>未复核</strong>";
                           
                        }
                        else if (ds.Tables[0].Rows[i]["IsBs"].ToString() == "1")
                        {
                            ds.Tables[0].Rows[i]["title"] = "<strong style='color:blue;'>已复核</strong>";
                            ds.Tables[0].Rows[i]["titles"] = "";
                        }
                        else if (ds.Tables[0].Rows[i]["IsBs"].ToString() == "2")
                        {
                            ds.Tables[0].Rows[i]["title"] = "";
                            ds.Tables[0].Rows[i]["titles"] = "";
                        }
                        ds.Tables[0].Rows[i]["titles"] = "<strong style='color:red; cursor:pointer' del='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' type='" + ds.Tables[0].Rows[i]["types"].ToString() + "' onclick='dels(this)'>删除</strong>";
                        int mods = i % 3;
                        switch (mods)
                        { 
                                
                            case 0:
                                xjc.Append("<tr>");
                                xjc.Append("<td title='" + ds.Tables[0].Rows[i]["IsBs"].ToString() + "'><img src=\"image/lb.jpg\" onclick=\"opne('" + ds.Tables[0].Rows[i]["ids"].ToString() + "','" + ds.Tables[0].Rows[i]["types"].ToString() + "')\" /><br /><input value='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' types = '" + ds.Tables[0].Rows[i]["types"].ToString() + "' type=\"checkbox\" />" + ds.Tables[0].Rows[i]["REALNAME"].ToString() + "<br />" + ds.Tables[0].Rows[i]["tjdate"] + "<br />" + ds.Tables[0].Rows[i]["title"].ToString() + "<br />" + ds.Tables[0].Rows[i]["titles"].ToString() + "</td>");
                                break;
                            case 1:
                                xjc.Append("<td title='" + ds.Tables[0].Rows[i]["IsBs"].ToString() + "'><img src=\"image/lb.jpg\" onclick=\"opne('" + ds.Tables[0].Rows[i]["ids"].ToString() + "','" + ds.Tables[0].Rows[i]["types"].ToString() + "')\"/><br /><input value='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' types='" + ds.Tables[0].Rows[i]["types"].ToString() + "' type=\"checkbox\" />" + ds.Tables[0].Rows[i]["REALNAME"].ToString() + "<br />" + ds.Tables[0].Rows[i]["tjdate"] + "<br />" + ds.Tables[0].Rows[i]["title"].ToString() + "<br />" + ds.Tables[0].Rows[i]["titles"].ToString() + "</td>");
                                break;
                            case 2:
                                xjc.Append("<td title='" + ds.Tables[0].Rows[i]["IsBs"].ToString() + "'><img src=\"image/lb.jpg\" onclick=\"opne('" + ds.Tables[0].Rows[i]["ids"].ToString() + "','" + ds.Tables[0].Rows[i]["types"].ToString() + "')\" /><br /><input value='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' types='" + ds.Tables[0].Rows[i]["types"].ToString() + "' type=\"checkbox\" />" + ds.Tables[0].Rows[i]["REALNAME"].ToString() + "<br />" + ds.Tables[0].Rows[i]["tjdate"] + "<br />" + ds.Tables[0].Rows[i]["title"].ToString() + "<br />" + ds.Tables[0].Rows[i]["titles"].ToString() + "</td>");
                                xjc.Append("</tr>");
                                break;
                        }
                    }
                    int len = ds.Tables[0].Rows.Count;
                    if (len % 3 != 0)
                    {
                        xjc.Append("</tr>");
                    }
                    xjc.Append("</table>");
                }
            }
            PostListS.DataSource = ds;
            PostListS.DataBind();
        }

        protected void LCallBack_Callback(object sender, NickLee.Web.UI.CallBackEventArgs e)
        {
            try
            {
                string type = e.Parameters[0].ToString();
                if (type == "5")
                {
                    byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
                    Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
                    Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];

                    string lgname = e.Parameters[1].ToString().Trim();
                    string date = e.Parameters[2].ToString().Trim();
                    string  value = e.Parameters[3].ToString().Trim();
                    string  jdate = e.Parameters[4].ToString().Trim();

                    //Hashtable htable = new Hashtable();
                    //htable.Add("@lgname","%"+lgname+"%");
                    //htable.Add("@date",date);
                    //htable.Add("@jdate", jdate);
                    //htable.Add("@value",value);
                    //htable.Add("@postid",users.CL_POSTID_PK.ToString());

                    string sql = "";
                    sql = "select *  from (select NCID as ids,types,IsBs,tjdate,''title,''titles ,USERNAME ,REALNAME,number from NongCun left join CL_USER_S on CL_USER_SOID = NCLGID where NCLGID in ( select CL_USER_SOID  from CL_USER_S where CL_POSTID_PK ='" + users.CL_POSTID_PK.ToString() + "'  )and IsDel = 0 union all select SQID as ids,types,IsBs,tjdate,''title,''titles ,USERNAME,REALNAME,number from SheQu left join CL_USER_S on CL_USER_SOID = SQLGID where SQLGID in ( select CL_USER_SOID  from CL_USER_S where CL_POSTID_PK ='" + users.CL_POSTID_PK.ToString() + "'  ) and IsDel = 0 union all  select QYID as ids,types ,IsBs,tjdate,''title,''titles ,USERNAME,REALNAME,number from QiYe left join CL_USER_S on CL_USER_SOID = QYLGID where QYLGID  in ( select CL_USER_SOID  from CL_USER_S where CL_POSTID_PK ='" + users.CL_POSTID_PK.ToString() + "' ) and IsDel = 0) a ";
                    sql += " where 1=1 ";
                    if (lgname != "" && lgname != null)
                    {
                        sql += " and a.USERNAME like '%" + lgname + "%'";
                    }
                    if (value != "" && value != null)
                    {
                        sql += " and a.IsBs = "+value;
                    }
                    if (date != null && date != "")
                    {
                        sql += " and a.tjdate >cast("+date+" as  datetime)";
                    }
                    if (jdate != null && jdate != "")
                    {
                        sql += " and a.tjdate <cast(" + jdate + " as  datetime)";
                    }

                    DataSet ds = Maticsoft.DBUtility.DbHelperSQL.Query(sql);
                    if (ds.Tables.Count > 0)
                    {

                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            xjc.Append("<table>");
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                if (ds.Tables[0].Rows[i]["IsBs"].ToString() == "0")
                                {
                                    ds.Tables[0].Rows[i]["title"] = "<strong style='color:red;'>未复核</strong>";
                                    //ds.Tables[0].Rows[i]["titles"] = "<strong style='color:red; cursor:pointer' del='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' type='" + ds.Tables[0].Rows[i]["types"].ToString() + "' onclick='dels(this)'>退回</strong>";
                                }
                                else if (ds.Tables[0].Rows[i]["IsBs"].ToString() == "1")
                                {
                                    ds.Tables[0].Rows[i]["title"] = "<strong style='color:blue;'>已复核</strong>";
                                    ds.Tables[0].Rows[i]["titles"] = "";
                                }
                                else if (ds.Tables[0].Rows[i]["IsBs"].ToString() == "2")
                                {
                                    ds.Tables[0].Rows[i]["title"] = "";
                                    ds.Tables[0].Rows[i]["titles"] = "";
                                }
                                ds.Tables[0].Rows[i]["titles"] = "<strong style='color:red; cursor:pointer' del='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' type='" + ds.Tables[0].Rows[i]["types"].ToString() + "' onclick='dels(this)'>删除</strong>";
                                int mods = i % 3;
                                switch (mods)
                                {

                                    case 0:
                                        xjc.Append("<tr>");
                                        xjc.Append("<td title='" + ds.Tables[0].Rows[i]["IsBs"].ToString() + "'><img src=\"image/lb.jpg\" onclick=\"opne('" + ds.Tables[0].Rows[i]["ids"].ToString() + "','" + ds.Tables[0].Rows[i]["types"].ToString() + "')\" /><br /><input value='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' types = '" + ds.Tables[0].Rows[i]["types"].ToString() + "' type=\"checkbox\" />" + ds.Tables[0].Rows[i]["REALNAME"].ToString() + "<br />" + ds.Tables[0].Rows[i]["tjdate"] + "<br />" + ds.Tables[0].Rows[i]["title"].ToString() + "<br />" + ds.Tables[0].Rows[i]["titles"].ToString() + "</td>");
                                        break;
                                    case 1:
                                        xjc.Append("<td title='" + ds.Tables[0].Rows[i]["IsBs"].ToString() + "'><img src=\"image/lb.jpg\" onclick=\"opne('" + ds.Tables[0].Rows[i]["ids"].ToString() + "','" + ds.Tables[0].Rows[i]["types"].ToString() + "')\"/><br /><input value='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' types='" + ds.Tables[0].Rows[i]["types"].ToString() + "' type=\"checkbox\" />" + ds.Tables[0].Rows[i]["REALNAME"].ToString() + "<br />" + ds.Tables[0].Rows[i]["tjdate"] + "<br />" + ds.Tables[0].Rows[i]["title"].ToString() + "<br />" + ds.Tables[0].Rows[i]["titles"].ToString() + "</td>");
                                        break;
                                    case 2:
                                        xjc.Append("<td title='" + ds.Tables[0].Rows[i]["IsBs"].ToString() + "'><img src=\"image/lb.jpg\" onclick=\"opne('" + ds.Tables[0].Rows[i]["ids"].ToString() + "','" + ds.Tables[0].Rows[i]["types"].ToString() + "')\" /><br /><input value='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' types='" + ds.Tables[0].Rows[i]["types"].ToString() + "' type=\"checkbox\" />" + ds.Tables[0].Rows[i]["REALNAME"].ToString() + "<br />" + ds.Tables[0].Rows[i]["tjdate"] + "<br />" + ds.Tables[0].Rows[i]["title"].ToString() + "<br />" + ds.Tables[0].Rows[i]["titles"].ToString() + "</td>");
                                        xjc.Append("</tr>");
                                        break;
                                }
                            }
                            int len = ds.Tables[0].Rows.Count;
                            if (len % 3 != 0)
                            {
                                xjc.Append("</tr>");
                            }
                            xjc.Append("</table>");
                        }
                    }
                    PostListS.DataSource = ds;
                    PostListS.DataBind();

                }
                else if (type == "1")
                {
                    string[] bsids = e.Parameters[1].ToString().Split('|');
                    string[] types = e.Parameters[2].ToString().Split('|');
                    if (bsids.Length > 1)
                    {
                        Hashtable htable = new Hashtable();
                        htable.Add("IsBs", "1");
                        SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                        string ty = "";
                        string tyid = "";
                        for (int i = 0; i < bsids.Length - 1; i++)
                        {

                            if (types[i] == "1")
                            {
                                ty = "NongCun";
                                tyid = "NCID";
                            }
                            else if (types[i] == "2")
                            {
                                ty = "SheQu";
                                tyid = "SQID";
                            }
                            else if (types[i] == "3")
                            {
                                ty = "QiYe";
                                tyid = "QYID";
                            }
                            dtable.databyhtables(htable, "update", ty, tyid, bsids[i]);
                        }
                    }
                    f_build();
                }
                else if (type == "del")
                {
                    string ids = e.Parameters[1].ToString();
                    string typ = e.Parameters[2].ToString();
                    string ty = "";
                    string tyid = "";
                    if (typ == "1")
                    {
                        ty = "NongCun";
                        tyid = "NCID";
                    }
                    else if (typ == "2")
                    {
                        ty = "SheQu";
                        tyid = "SQID";
                    }
                    else if (typ == "3")
                    {
                        ty = "QiYe";
                        tyid = "QYID";
                    }

                    Hashtable htable = new Hashtable();
                    htable.Add("IsDel", "1");
                    SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();

                    dtable.databyhtables(htable, "update", ty, tyid, ids);
                

                    f_build();
                }
                else if(type=="yc")
                {
                    xjc.Clear();
                    DataSet ds = new DataSet();
                    byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
                    Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
                    Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];
                    Hashtable htable = new Hashtable();
                    htable.Add("@postid", users.CL_POSTID_PK.ToString());
                    if (ywfh.Checked == false && yfh.Checked == false)
                    {

                        ds = new SqlReadXml().ReaderDataSet("sel_TB_HDQK_al", htable);
                       
                    }
                    else if (ywfh.Checked == false && yfh.Checked == true)
                    {
                        ds = new SqlReadXml().ReaderDataSet("sel_TB_HDQK_alls", htable);
                    }
                    else if (ywfh.Checked == true && yfh.Checked == false)
                    {
                        ds = new SqlReadXml().ReaderDataSet("sel_TB_HDQK_a", htable);
                    }
                    else if (ywfh.Checked == true && yfh.Checked == true)
                    {
                        ds = new SqlReadXml().ReaderDataSet("sel_TB_HDQK_aa", htable);
                    }

                    if (ds.Tables.Count > 0)
                    {

                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            xjc.Append("<table>");
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                if (ds.Tables[0].Rows[i]["IsBs"].ToString() == "0")
                                {
                                    ds.Tables[0].Rows[i]["title"] = "<strong style='color:red;'>未复核</strong>";
                                    // ds.Tables[0].Rows[i]["titles"] = "<strong style='color:red; cursor:pointer' del='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' type='" + ds.Tables[0].Rows[i]["types"].ToString() + "' onclick='dels(this)'>退回</strong>";
                                }
                                else if (ds.Tables[0].Rows[i]["IsBs"].ToString() == "1")
                                {
                                    ds.Tables[0].Rows[i]["title"] = "<strong style='color:blue;'>已复核</strong>";
                                    ds.Tables[0].Rows[i]["titles"] = "";
                                }
                                else if (ds.Tables[0].Rows[i]["IsBs"].ToString() == "2")
                                {
                                    ds.Tables[0].Rows[i]["title"] = "";
                                    ds.Tables[0].Rows[i]["titles"] = "";
                                }
                                ds.Tables[0].Rows[i]["titles"] = "<strong style='color:red; cursor:pointer' del='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' type='" + ds.Tables[0].Rows[i]["types"].ToString() + "' onclick='dels(this)'>删除</strong>";
                                int mods = i % 3;
                                switch (mods)
                                {

                                    case 0:
                                        xjc.Append("<tr>");
                                        xjc.Append("<td title='" + ds.Tables[0].Rows[i]["IsBs"].ToString() + "'><img src=\"image/lb.jpg\" onclick=\"opne('" + ds.Tables[0].Rows[i]["ids"].ToString() + "','" + ds.Tables[0].Rows[i]["types"].ToString() + "')\" /><br /><input value='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' types = '" + ds.Tables[0].Rows[i]["types"].ToString() + "' type=\"checkbox\" />" + ds.Tables[0].Rows[i]["REALNAME"].ToString() + "<br />" + ds.Tables[0].Rows[i]["tjdate"] + "<br />" + ds.Tables[0].Rows[i]["title"].ToString() + "<br />" + ds.Tables[0].Rows[i]["titles"].ToString() + "</td>");
                                        break;
                                    case 1:
                                        xjc.Append("<td title='" + ds.Tables[0].Rows[i]["IsBs"].ToString() + "'><img src=\"image/lb.jpg\" onclick=\"opne('" + ds.Tables[0].Rows[i]["ids"].ToString() + "','" + ds.Tables[0].Rows[i]["types"].ToString() + "')\"/><br /><input value='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' types='" + ds.Tables[0].Rows[i]["types"].ToString() + "' type=\"checkbox\" />" + ds.Tables[0].Rows[i]["REALNAME"].ToString() + "<br />" + ds.Tables[0].Rows[i]["tjdate"] + "<br />" + ds.Tables[0].Rows[i]["title"].ToString() + "<br />" + ds.Tables[0].Rows[i]["titles"].ToString() + "</td>");
                                        break;
                                    case 2:
                                        xjc.Append("<td title='" + ds.Tables[0].Rows[i]["IsBs"].ToString() + "'><img src=\"image/lb.jpg\" onclick=\"opne('" + ds.Tables[0].Rows[i]["ids"].ToString() + "','" + ds.Tables[0].Rows[i]["types"].ToString() + "')\" /><br /><input value='" + ds.Tables[0].Rows[i]["ids"].ToString() + "' types='" + ds.Tables[0].Rows[i]["types"].ToString() + "' type=\"checkbox\" />" + ds.Tables[0].Rows[i]["REALNAME"].ToString() + "<br />" + ds.Tables[0].Rows[i]["tjdate"] + "<br />" + ds.Tables[0].Rows[i]["title"].ToString() + "<br />" + ds.Tables[0].Rows[i]["titles"].ToString() + "</td>");
                                        xjc.Append("</tr>");
                                        break;
                                }
                            }
                            int len = ds.Tables[0].Rows.Count;
                            if (len % 3 != 0)
                            {
                                xjc.Append("</tr>");
                            }
                            xjc.Append("</table>");
                        }
                        PostListS.DataSource = ds;
                        PostListS.DataBind();

                    }
               

                   

                }
 
            }
            catch (Exception ee)
            {
                throw ee;
            }
            finally
            {
               
                Panel1.RenderControl(e.Output);
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string[] bsids = this.bsids.Value.Split('|');
            string[] types =  this.types.Value.Split('|');
            if (bsids.Length > 1)
            {
                SqlReadXml sql = new SqlReadXml();
                
                Hashtable htable = new Hashtable();
                //htable.Add("IsBs", "1");
                //SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                //string ty = "";
                //string tyid = "";
                for (int i = 0; i < bsids.Length - 1; i++)
                {
                    htable.Clear();
                    htable.Add("@id", bsids[i]);
                    if (types[i] == "1")
                    {
                        sql.NotDoSQL("update_NC", htable);
                      
                    }
                    else if (types[i] == "2")
                    {
                        sql.NotDoSQL("update_SQ", htable);
                    }
                    else if (types[i] == "3")
                    {
                        sql.NotDoSQL("update_QY", htable);
                    }
                    //dtable.databyhtables(htable, "update", ty, tyid, bsids[i]);
                }
            }
            f_build();
        }
    }
}